|
|
 |
|
|
|
|
If t1 < 0.02 Then
RayTraceable_FindT = -1
Exit Function
End If
' See where on the cylinder this point is. HitU = t1 * A + B
' If this is not between Point1 and Point2,
' ignore it. If HitU < 0 Or HitU > 1 Then
RayTraceable_FindT = -1
Else
RayTraceable_FindT = t1
End If
End Function |
|
|
|
|
|
|
|
|
The FindHitColor function for cylinders is similar to the corresponding functions for other objects. The main difference is in how the function calculates the surface normal vector. For a cylinder, the function uses the values of t and u to find the points H and I as shown in Figure 17.18. The vector from point I to point H is normal to the surface at the point of intersection. |
|
|
|
|
|
|
|
|
When it finds a point of intersection, function FindT saves the value of u in the module global variable HitU. Rather than recalculating the value u to find the normal vector, subroutine FindHitColor uses the value in HitU. It can then find the normal vector and pass it into the CalculateHitColor subroutine. |
|
|
|
 |
|
|
|
|
' Return the red, green, and blue components of
' the surface at the hit position. Public Sub RayTraceable_FindHitColor( _
ByVal depth As Integer, Objects As Collection, _
ByVal eye_x As Single, ByVal eye_y As Single, _
ByVal eye_z As Single, ByVal px As Single, _
ByVal py As Single, ByVal pz As Single, _
ByRef R As Integer, ByRef G As Integer, _
ByRef B As Integer)
Dim Vx As Single
Dim Vy As Single
Dim Vz As Single
Dim Nx As Single
Dim Ny As Single
Dim Nz As Single
Dim n_len As Single
' Find the unit normal at this point. Vx = Point2.Trans(1) - Point1.Trans(1)
Vy = Point2.Trans(2) - Point1.Trans(2)
Vz = Point2.Trans(3) - Point1.Trans(3)
Nx = px - (Point1.Trans(1) + HitU * Vx)
Ny = py - (Point1.Trans(2) + HitU * Vy) |
|
|
|
|
|